import {
	getRequest,
	postRequest,
} from '../request.js'
import store from '@/store'

export const login = (params) => {
	return postRequest('/user/login', params)
}

export const register = (params) => {
	return postRequest('/user/register', params)
}

export const detail = (params) => {
	return getRequest('/user/detail', params)
}

export const personalDetail = (params) => {
	return getRequest('/user/getPersonalDetail', params)
}

export const personalResume = (params) => {
	return getRequest('/resume/detail', params)
}

export const personalResumeList = (params) => {
	return getRequest('/resume/list', params)
}

export const personalDetailById = (params) => {
	return getRequest('/user/getPersonalDetailById', params)
}

export const saveResume = (params) => {
	return postRequest('/resume/save', params)
}

export const resumePageSearch = (params) => {
	return getRequest('/resume/pageSearch', params)
}

export const getUserInfo = (userId) => {
	return getRequest('/user/info', { userId })
}

export const updateUserInfo = (params) => {
	return postRequest('/user/update', params)
}

export const uploadFile = (filePath) => {
	return new Promise((resolve, reject) => {
		uni.uploadFile({
			url: 'http://localhost:1110/ZHLG/upload/avatar',
			filePath: filePath,
			name: 'file',
			header: {
				'token': store.getters.getToken || ''
			},
			success: (res) => {
				const data = JSON.parse(res.data)
				if (data.code === 200) {
					// 直接返回文件URL
					resolve({
						url: data.data
					})
				} else {
					reject(new Error(data.message))
				}
			},
			fail: reject
		})
	})
}